package graduate.wangyaqi.OnlyQuestions;

import graduate.wangyaqi.Taoti.Taoti;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Optional;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping(path="/OnlyQuestions")
public class OnlyQuestionsController {
    @Autowired
    private OnlyQuestionsService onlyQuestionsService;

    @GetMapping(path="/getAllByTaotiID")
    public Iterable<OnlyQuestions> getAllByTaotiID(long id){
        Iterable<OnlyQuestions> onlyQuestions = onlyQuestionsService.getAllByTaotiID(id);
        return onlyQuestions;
    }


    @GetMapping(path="/delete")
    public @ResponseBody
    void Del(Long id) {
        onlyQuestionsService.delete(id);
    }


    @PostMapping(path="/save")
    public boolean save(@RequestBody OnlyQuestions onlyQuestions){
        onlyQuestions.setJointime(new Date());
        onlyQuestionsService.save(onlyQuestions);
        return true;
    }

    @GetMapping(path="/findById")
    public Optional<OnlyQuestions> findById(Long aLong){
        return onlyQuestionsService.findById(aLong);
    }
}
